# 首先 import 必要的模块
import pandas as pd
import numpy as np

from sklearn.model_selection import GridSearchCV

import matplotlib.pyplot as plt

from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import LogisticRegression

# 读取经过特征工程的数据文件
train = pd.read_csv('FE_pima-indians-diabetes.csv')

y_train = train['Target']
X_train = train.drop(["Target"], axis=1)

#需要调优的参数
# 请尝试将L1正则和L2正则分开，并配合合适的优化求解算法（slover）
penaltys = ['l1','l2']

#训练数据多，C可以大一点
Cs = [0.01, 0.1, 1, 10, 100, 1000, 10000]

tuned_parameters = dict(penalty = penaltys, C = Cs)#组合调优参数

lr_penalty= LogisticRegression()
grid= GridSearchCV(lr_penalty, tuned_parameters,cv=5, scoring='neg_log_loss')#log似然损失
# grid= GridSearchCV(lr_penalty, tuned_parameters,cv=5, scoring='accuracy')#正确率
grid.fit(X_train,y_train)

print(-grid.best_score_)#打印模型参数
print(grid.best_params_)
